package com.study.mqTest.queue;

import org.apache.activemq.ActiveMQConnectionFactory;

import javax.jms.*;

public class Product {

    private static final String URL;

    private static final String USERNAME;

    private static final String PASSWORD;

    static {
        URL = "tcp://127.0.0.1:61616";
        USERNAME = "admin";
        PASSWORD = "admin";
    }



    public static void main(String[] args) {
        ActiveMQConnectionFactory activeMQConnectionFactory = new ActiveMQConnectionFactory(URL);

        try {
            Connection connection = activeMQConnectionFactory.createConnection();
            connection.start();
            Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
            Queue queue = session.createQueue("myQueue01");

            MessageProducer producer = session.createProducer(queue);
            for (int i = 0; i < 8; i++) {
                TextMessage message = session.createTextMessage("发送消息" + i);
                producer.send(message);
            }
            session.close();
            connection.close();
        } catch (JMSException e) {
            e.printStackTrace();


        }

    }

}
